package ma.controller.panels;

import java.util.ArrayList;
import java.util.List;

import ma.controller.gui.Controllable;
import ma.controller.panels.auxillary.CtrInformationPanel;
import ma.controller.panels.parameterpanels.CtrGeoPanelMWGDE;
import ma.controller.panels.parameterpanels.CtrProcessPanelMWGDE;
import ma.controller.panels.parameterpanels.CtrMMResults;
import ma.model.ManufacturingMethodInterface.SuperType;
import ma.model.ManufacturingMethodInterface;
import ma.view.gui.EBenchmarkPanel;

/**
 * The {@code CtrInOutController} creates controllers that control the views of
 * a manufacturing method. The controllers get created based on the {@code
 * SuperType} of the {@code ManufacturingMethodInterface}.
 * @author Oliver Eckstein
 *
 */
public class CtrInOut {
    private ManufacturingMethodInterface manuMethod;
    private CtrInformationPanel infoPanelController;
    private CtrMMResults resultParameterPanelController;
    private List<EBenchmarkPanel> theViews = new ArrayList<EBenchmarkPanel>();
    
    /**
     * To create a new instance of a {@code CtrInOutController} and connect it
     * to the model and the controller of the information panel.
     * @param manuMethod the manufacturing method which gets connected to the
     * views of this controller.
     * @param infoPanelController the controller of the information panel.
     */
    public CtrInOut(
            ManufacturingMethodInterface manuMethod,
            CtrInformationPanel infoPanelController) {
        this.manuMethod = manuMethod;
        this.infoPanelController = infoPanelController;
        createControllers();
    }
    
    /**
     * Creates the input and output controllers.
     */
    private void createControllers() {        
        // TODO This has to be extended when new manufacturing method types get implemented.
        
        // Machining with geometrically defined edges
        if (manuMethod.getSuperType() ==
                SuperType.MANUFACTURING_GEOMETRICALLY_DEFINED_EDGES) {
            
            Controllable controller = 
                    new CtrProcessPanelMWGDE(
                            manuMethod,
                            infoPanelController);
            theViews.add(controller.getView());
            
            controller =
                    new CtrGeoPanelMWGDE(
                            manuMethod,
                            infoPanelController);
            theViews.add(controller.getView());
            
            resultParameterPanelController =
                    new CtrMMResults(
                            manuMethod,
                            infoPanelController);            
            theViews.add(resultParameterPanelController.getView());
        }                
    }
    
    /**
     * To get the controller of the intermediate result parameter panel.
     * @return
     */
    public CtrMMResults getResultParameterPanelController() {
        return resultParameterPanelController;
    }
    
    /**
     * To get all views created by this controller.
     * @return the controller's views.
     */
    public List<EBenchmarkPanel> getViews() {
        return theViews;
    }
}
